package net.oschina.app.adapter.me.messageAdapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.MessagesBean;
import net.oschina.app.ui.activity.DetailActivity;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class LeaveMessageListAdapter extends BaseListAdapter<MessagesBean.MessageBean> {
    private String mUrl;
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_me_message_leavemessage,parent,false);
        LeaveMessageHolder holder = new LeaveMessageHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MessagesBean.MessageBean  data =  mList.get(position);
        ((LeaveMessageHolder)holder).tvName.setText(data.getFriendname());
        ((LeaveMessageHolder)holder).tvContent.setText(data.getContent());
        ((LeaveMessageHolder)holder).tvData.setText(data.getPubDate());
        ((LeaveMessageHolder)holder).tvCount.setText(data.getMessageCount()+"条留言");
//        mUrl = data.getu();
    }

    class LeaveMessageHolder extends RecyclerView.ViewHolder{
        public TextView tvName;
        public TextView tvContent;
        public TextView tvData;
        public TextView tvCount;
        public LeaveMessageHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_message_name);
            tvContent = (TextView) itemView.findViewById(R.id.tv_message_content);
            tvData = (TextView) itemView.findViewById(R.id.tv_message_pubDate);
            tvCount= (TextView) itemView.findViewById(R.id.tv_message_count);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Global.mContext, DetailActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url",mUrl);
                    Global.mContext.startActivity(intent);
                }
            });
        }
    }
}
